package com.java.zhuiyun.api.file_manager.mapper;

import com.java.zhuiyun.api.file_manager.entity.FileManager;
import com.java.zhuiyun.common.mapper.BaseMapper;
import com.java.zhuiyun.util.pageUtil.PageRequest;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.annotations.Param;

import java.util.List;

@Mapper
public interface FileManagerMapper extends BaseMapper<FileManager> {
    /**
    * @Author MJL
    * @Description todo 分页查询所有文件信息
    * @Date 2023/8/15 20:58
    * @Return  * @param null
    */
//    @Select("SELECT f.* , u.nick_name FROM file_manager f \n" +
//            "INNER JOIN sys_user u ON f.uploaded_by = u.id \n" +
//            "WHERE f.del_flag = 0 AND f.audit_type = 1 \n" +
//            "ORDER BY create_time DESC")
   @Select("SELECT f.* , u.nick_name " +
           "FROM file_manager f " +
           "INNER JOIN sys_user u " +
           "ON f.uploaded_by = u.id " +
           "WHERE u.id = #{id} " +
           "AND f.del_flag = 0 " +
           "AND f.audit_type = 1 " +
           "ORDER BY create_time DESC")
    List<FileManager> queryFile(@Param("fileManagerName") String fileManagerName, @Param("pageRequest") PageRequest pageRequest, @Param("id") Integer id);

    /**
    * @Author MJL
    * @Description 上传文件
    * @Date 2023/8/16 9:23
    * @Return  * @param null
    */
    @Insert("insert into file_manager (file_manager_name,file_path,size,audit_type,file_type," +
            "create_time,update_time,del_flag) values (#{fileManagerName},#{filePath}," +
            "#{size},#{auditType},#{fileType},#{createTime},#{updateTime},#{delFlag})")
    int saveFileManager(FileManager fileManager);

    /**
    * @Author MJL
    * @Description 下载文件
    * @Date 2023/8/22 9:18
    * @Return  * @param null
    */
    @Select("select * from file_manager where file_manager_id = #{fileManagerId}")
    FileManager downLoadFile(Integer fileManagerId);

    /**
    * @Author MJL
    * @Description todo 根据登录信息查询文件
    * @Date 2023/8/30 8:43
    * @Return  * @param null
    */
    @Select("SELECT f.* , u.nick_name FROM file_manager f " +
            "INNER JOIN sys_user u ON f.uploaded_by = u.id " +
            "WHERE f.del_flag = 0 AND f.audit_type = 1 " +
            "and uploaded_by = #{uploadedBy}")
    FileManager getFileById(Integer uploadedBy);

    /**
    * @Author MJL
    * @Description todo 删除教师上传的视频
    * @Date 2023/9/1 14:06
    * @Return  * @param null
    */
    @Update("update file_manager set del_flag = 1 where file_manager_id = #{fileManagerId}")
    int deleteFileManage(Integer fileManagerId);
}
